package com.dy.service.impl;

import com.dy.dao.UserDao;
import com.dy.domain.User;
import com.dy.exception.BusinessException;
import com.dy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public boolean add(User user) {
        return userDao.add(user) > 0;
    }

    @Override
    public boolean update(User user) {
        return userDao.update(user) > 0;
    }

    @Override
    public boolean deleteById(Integer uId) {
        //检查用户输入是否合法，否则抛出业务异常，提醒用户
        if (uId <= 0) {
            throw new BusinessException();
        }
        return userDao.deleteById(uId) > 0;
    }

    @Override
    public User getById(Integer uId) {
        //检查用户输入是否合法，否则抛出业务异常，提醒用户
        if (uId <= 0) {
            throw new BusinessException();
        }
        return userDao.getById(uId);
    }

    @Override
    public List<User> getAll() {
        return userDao.getAll();
    }
}
